package com.qumap.server;

import com.qumap.item.content.ObjectOnMapShort;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 26.06.11
 * Time: 18:22
 * To change this template use File | Settings | File Templates.
 */
public abstract class LoadProcessorHelper<T extends ObjectOnMapShort> extends FilterProcessorHelper {

    private Map<Integer, T> item_map;

    public abstract T buildContent();

    @Override
    protected void init() {
        item_map = new HashMap<Integer, T>();
        super.init();
    }

    @Override
    protected ObjectOnMapShort generateObject(int index) {
        ObjectOnMapShort generated_item = super.generateObject(index);
        T new_item = buildContent();
        generated_item.putTo(new_item);
        initItem(new_item);
        item_map.put(index, new_item);

        return generated_item;
    }

    public void initItem(T new_item) {

    }



    public T getObject(Integer object_index) {
        T mapped_object =  item_map.get(object_index);
        if(mapped_object == null)
            throw new NullPointerException("There is no elements with such id "+object_index);
        return mapped_object;
    }
}
